from abc import ABC, abstractmethod
from typing import Optional

from pydantic import Field

from app.agent.base import BaseAgent



class ReActAgent(BaseAgent, ABC):
    """
    这个类有点类似java中的抽象类， 里面使用模版方法
    1. 智能体自己先根据提示词进行想问题如何执行， 需要哪些动作
    2. 根据前一步想好的进行动作进行执行
    """
    name: str
    description: Optional[str] = None

    system_prompt: Optional[str] = None
    next_step_prompt: Optional[str] = None

    # llm: Optional[LLM] = Field(default_factory=LLM)
    # memory: Memory = Field(default_factory=Memory)
    # state: AgentState = AgentState.IDLE

    max_steps: int = 10
    current_step: int = 0

    @abstractmethod
    async def think(self) -> bool:
        """Process current state and decide next action"""

    @abstractmethod
    async def act(self) -> str:
        """Execute decided actions"""

    async def step(self) -> str:
        """Execute a single step: think and act."""
        should_act = await self.think()
        if not should_act:
            return "Thinking complete - no action needed"
        return await self.act()
